/**
 * Created by jimmy on 2017/6/10.
 */

var mysqlConn = require("./BaseDao");

exports.getProdList = function (typeId,callbk) {
    mysqlConn.getConn(function (err,connection) {
        connection.query("select * from product where product_type_id = ?",[typeId],function (err,rows) {
            connection.release();
            console.log(err);
            callbk(err,rows);
        })
    });
}

exports.getTypeList = function (callbk) {
    mysqlConn.getConn(function (err,connection) {
        connection.query("select * from product_type",[],function (err,rows) {
            connection.release();
            callbk(err,rows);
        })
    });
}

exports.getProd = function (prodId,callbk) {
    mysqlConn.getConn(function (err,connection) {
        connection.query("select * from product where product_id = ?",[prodId],function (err,rows) {
            connection.release();
            callbk(err,rows);
        })
    });
}

exports.getProdDetail = function (prodId,dtype,callbk) {
    mysqlConn.getConn(function (err,connection) {
        connection.query("select * from product_detail where product_id in ("+prodId+") and type = ?",[dtype],function (err,rows) {
            connection.release();
            callbk(err,rows);
        })
    });
}

exports.getMainProd = function (callbk) {
    mysqlConn.getConn(function (err,connection) {
        connection.query("select a.*,b.`value` as mpic from product a left join product_detail b on a.product_id = b.product_id and b.`type`='mpic' where a.product_is_main = 1",null,function (err,rows) {
            connection.release();
            callbk(err,rows);
        })
    });
}